package utils

import com.typesafe.config.ConfigFactory
import org.apache.commons.pool2.impl.GenericObjectPoolConfig
import redis.clients.jedis.{Jedis, JedisPool}

/**
  * Created by Administrator on 2018/03/25.
  */
object Jedis {

  private val load = ConfigFactory.load()
  private val genericObjectPoolConfig = new GenericObjectPoolConfig()
  genericObjectPoolConfig.setMaxIdle(10)
  genericObjectPoolConfig.setMaxTotal(200)

  private lazy val jedisPool = new JedisPool(genericObjectPoolConfig,
    load.getString("cmcc.redis.host"),
    load.getInt("cmcc.redis.port"),
    load.getInt("timeOut"),
    null,
    load.getInt("cmcc.redis.index")
  )

  def getJedis: Jedis = jedisPool.getResource




}
